package book.nettyinaction.ch06;

import io.netty.channel.*;

/**
 *
 * 代码清单 6-14 添加 ChannelFutureListener 到 ChannelPromise
 *
 */
public class OutboundExceptionHandler extends ChannelOutboundHandlerAdapter {

    @Override
    public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
        promise.addListener(new ChannelFutureListener() {
            @Override
            public void operationComplete(ChannelFuture future) throws Exception {
                if ( !future.isSuccess() ) {
                    future.cause().printStackTrace();
                    future.channel().close();
                }
            }
        });
    }
}
